﻿#region Header

/*
Behavioral Rating of Dancing Human Crowds based on Motion Patterns
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using Microsoft.VisualStudio.TestTools.UnitTesting;
using paravili.Steps;

#endregion

namespace Tests.Basics.Steps {
	/// <summary>
	/// Description of the class
	/// </summary>
	[TestClass]
	public class TestStringToConditionConverter {
		#region Test Methods

		// public methods located here

		[TestMethod]
		public void TestParseEmptyConditionIsNull() {
			var testCandidate = new StringToConditionConverter();

			string input = string.Empty;

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsNull(output);
		}

		[TestMethod]
		public void TestParseNullConditionIsNull() {
			var testCandidate = new StringToConditionConverter();

			string input = null;

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsNull(output);
		}

		[TestMethod]
		public void TestParseConditionWithResultWithSpace() {
			var testCandidate = new StringToConditionConverter();

			string input = "--> Good";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsTrue(output.TrueConditionResult.Value == "Good");
		}

		[TestMethod]
		public void TestParseConditionWithResultWithoutSpace() {
			var testCandidate = new StringToConditionConverter();

			string input = "-->Good";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsTrue(output.TrueConditionResult.Value == "Good");
		}

		[TestMethod]
		public void TestParseConditionWithNoResult() {
			var testCandidate = new StringToConditionConverter();

			string input = "value > 50";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsNull(output);
		}

		[TestMethod]
		public void TestParse50Bigger20ConditionWithResult() {
			var testCandidate = new StringToConditionConverter();

			string input = "50 > 20 --> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			//IsTrue input value is not used! should allways assert to true as 50>20
			Assert.IsTrue(output.IsTrue(10));
		}

		[TestMethod]
		public void TestParse50BiggerValueConditionTrueWithResult() {
			var testCandidate = new StringToConditionConverter();

			string input = "50 > value --> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsTrue(output.IsTrue(10));
		}

		[TestMethod]
		public void TestParse50BiggerValueConditionFalseWithResult() {
			var testCandidate = new StringToConditionConverter();

			string input = "50 > value --> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsFalse(output.IsTrue(50));
		}

		[TestMethod]
		public void TestParseValueEqualValueConditionFalseWithResult() {
			var testCandidate = new StringToConditionConverter();

			string input = "value = value --> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsTrue(output.IsTrue(50));
		}

		[TestMethod]
		public void TestParse20NotEqual50ConditionFalseWithResult() {
			var testCandidate = new StringToConditionConverter();

			string input = "20 <> 50 --> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsTrue(output.IsTrue(50));
		}

		[TestMethod]
		public void TestParse20SmallerEqualAs50() {
			var testCandidate = new StringToConditionConverter();

			string input = "20 <= 50 --> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsTrue(output.IsTrue(50));
		}

		[TestMethod]
		public void TestParse20GreaterEqualAs50() {
			var testCandidate = new StringToConditionConverter();

			string input = "20 >= 50 --> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsFalse(output.IsTrue(50));
		}

		[TestMethod]
		public void TestParseMultipleCondition1() {
			var testCandidate = new StringToConditionConverter();

			string input = "value >= 50 && value < 70--> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsTrue(output.IsTrue(60));
		}

		[TestMethod]
		public void TestParseMultipleCondition2() {
			var testCandidate = new StringToConditionConverter();

			string input = "value >= 50 && value < 70--> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsFalse(output.IsTrue(70));
		}

		[TestMethod]
		public void TestParseMultipleCondition3() {
			var testCandidate = new StringToConditionConverter();

			string input = "value >= 50 && value < 70 && value <= 60 --> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsTrue(output.IsTrue(60));
		}

		[TestMethod]
		public void TestParseMultipleCondition4() {
			var testCandidate = new StringToConditionConverter();

			string input = "value <> 50 && value < 70 && value <= 60 --> True";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsFalse(output.IsTrue(50));
		}

		[TestMethod]
		public void TestParseMultipleCondition5() {
			var testCandidate = new StringToConditionConverter();

			string input = "value > 0 && value <= 20 --> Michi ist da";

			AndBasedLinkedConditions output = testCandidate.ConvertToCondition(input);

			Assert.IsTrue(output.IsTrue(3));
		}

		#endregion
	}
}